<template>
  <page-wrap stay-still back hide-tab title="职位详情">
    <view class="job-detail">
      <view :class="{ 'jd-wrap': true, 'not-company': notCompany }">
        <view class="jd-consultant jd-sect" @click="handleConsultantEntranceClick">
          <view class="jd-consultant-container">
            <view class="market-icon">
              <img :src="consultant_entrance_hot" alt="" />
            </view>
            <view class="market-main-text">找工作</view>
            <view class="market-sub-text">心仪offer，入职涨薪</view>
          </view>
          <view class="market-button">咨询顾问</view>
        </view>
        <view class="jd-info jd-sect">
          <view class="info-top">
            <text class="info-name">{{ info.jtzw }}</text>
            <text class="info-salary">{{ info.xzdy }}</text>
          </view>
          <view class="info-middle">
            <text class="info-region">{{ info.regionid_name }}</text>
            <text class="info-exp">{{ info.gznum }}</text>
            <text class="info-edu">{{ info.edus }}</text>
            <text class="info-type">{{ info.jobtypes }}</text>
          </view>
          <view class="info-bottom">
            <text class="info-time">{{ info.updatetime | timeFilter }}</text>
          </view>
        </view>

        <view class="account-box" @click="toChat">
          <image class="header-pic" :src="headerPic" />
          <view class="account-box-right">
            <view class="account-box-right-item">
              <text class="text-item"> {{ publishPersonInfo.iname }} </text>
              <text class="text-item">
                {{ publishPersonInfo.activeTime }}
              </text>
            </view>
            <view class="account-box-right-item">
              <text class="text-item"> {{ calculateCompanyName }} </text>
              <text class="text-item"> {{ publishPersonInfo.pnames }} </text>
            </view>
          </view>
        </view>

        <view class="tx-job" v-if="isTXJob" @click="copyText(TXUrls)">
          若投递本岗位，请登陆 【腾讯校招平台： {{ TXUrls }} 】注册简历并投递。
        </view>

        <view class="jd-request jd-sect">
          <view class="jr-title"><text class="icon icon-require"></text>职位要求
            <view class="customized-resume" @click="handleCustomizedResume">
              <view class="icon icon-analysis"></view>
              定制简历</view>
          </view>
          <view class="jr-cont u-border-top" v-html="formatHtml(zpDetail.zptxt) || '暂无'"></view>
        </view>
        <view class="jd-company jd-sect" @click="handleCompany">
          <view class="jc-info">
            <view class="info-avatar">
              <image mode="aspectFill" :src="comapnyDetail.logopath"></image>
            </view>
            <view class="info-desc">
              <view class="id-name">{{ info.cname_all }}</view>
              <view class="id-trade">{{
                comapnyDetail.trade || '其他行业'
              }}</view>
              <view class="id-other">
                <text class="type">{{
                  comapnyDetail.cxz || '其他企业性质'
                }}</text>
                <text class="divider"></text>
                <text class="scale">{{
                  comapnyDetail.yuangong || '其他企业规模'
                }}</text>
              </view>
            </view>
          </view>
          <view class="jc-region u-border-top" v-if="comapnyDetail.address">{{
            comapnyDetail.address
          }}</view>
        </view>
        <view class="jd-benefit jd-sect" v-if="comapnyTags && comapnyTags.length">
          <text class="jb-item" v-for="(item, index) in comapnyTags" :key="index">{{ item.ylt_name }}</text>
        </view>

        <view class="offer-advbox" v-if="isFromEnterprisesActivityHoverBtn" @click="handleOfferBannerClick">
        </view>

      </view>

      <view class="jd-option" v-if="notCompany">
        <button class="option-rich share" open-type="share" @click="handleWeChat" v-if="shareList.length">
          分享
        </button>
        <!-- <view
          class="option-rich share"
          @click="showShare = true"
          v-if="shareList.length"
          >分享</view
        > -->
        <view :class="['option-rich collect', { active: isCollected }]" @click="handleCollect">
          {{ isCollected ? '已收藏' : '收藏' }}</view>
        <template v-if="!isTXJob">
          <u-button v-if="canTalk" class="option-btn chat" @click="handleChat">立即沟通</u-button>
          <u-button :type="canApply ? 'primary' : 'info'" :class="['option-btn', 'deliver']" @click="handleDeliver">
            {{ deliverText }}</u-button>
        </template>
      </view>
    </view>
    <u-popup v-model="showShare" mode="bottom" safe-area-inset-bottom>
      <button class="share-item u-border-bottom" v-for="(item, index) in shareList" :key="index" :open-type="item.type"
        @click="handleShare(item)">
        {{ item.text }}
      </button>
      <button class="share-item close" @click="showShare = false">取消</button>
    </u-popup>
    
    <LoginDialog ref="loginDialog" @loginSuccessBack="loginSuccessBack"></LoginDialog>
    <ResumeDeliverDialog ref="resumeDeliverDialog" @deliverySuccess="hanldeDeliverySuccess"></ResumeDeliverDialog>
    <OfferInfoPopup :hasBtn="offerparTypeHasBtn" :show="isShowOfferInfoPopup" @close="isShowOfferInfoPopup=false" @waiveClick="handleOfferInfoPopupwaiveClick"></OfferInfoPopup>
    <u-popup v-model="customizedResumeDialog" mode="bottom" border-radius="14" closeable safe-area-inset-bottom	>
      <view class="resume-popup">
        <view class="customized-resume-title">定制简历</view>
        <view class="resume-popup-bg"></view>
        <view class="resume-popup-bg-2"></view>
        <view class="text">
          Hi，欢迎使用“定制简历”，您可以上传已有的简历文件，我们将根据您的情况，结合当前职位要求，生成一份新简历，新简历与此职位的契合度更高，更容易通过简历筛选哦！
        </view>
        <view class="text text-bottom">
          如果您还没有简历，可以点击“开始对话”，我们会简单提1-3个问题，了解您的基本情况，根据您的回答生成一份新简历！
        </view>
        <view class="customized-action" v-if="!isShowFile">
          <view class="btn-start-chat" @click="handleChatToCustomizedResume">开始对话
          </view>
          <view class="btn-upload-resume" @click="handleUploadResume">上传简历文件</view>
        </view>
        <view class="resume-file" v-if="isShowFile">
          <view class="file-item">
            <text class="icon icon-file"></text>
            <view class="flex-1">
              <text class="file-name u-line-2">{{ file.name }}</text>
              <text class="file-size">{{ file.size }}</text>
            </view>
            <view>
              <text class="change-file" @click="handleUploadResume">更换</text>
              <u-button type="primary" size="mini" :loading="uploadLoading" @click="handleStartCustomized">开始定制</u-button>
            </view>
          </view>
          <view class="start-chat" @click="handleChatToCustomizedResume">开始对话</view>
        </view>
      </view>
		</u-popup>
    <u-popup v-model="chatResumeDialog" mode="bottom" border-radius="14" closeable safe-area-inset-bottom	>
      <ChatResume ref="chatResume" :zpId="zp_id" :jobName="info.jtzw" :personId="personId" :pic="selfInfo.pic"></ChatResume>
    </u-popup>
  </page-wrap>
</template>

<script>
import IMEventHandler from "@/utils/im";
import { formatHtml, httpToHttps } from "@/utils/handle";
import {
  getZpDetailAndApplyStatus,
  batchGetBingdingPersonInfo,
  getZpTxtDetail,
  getComapnyTags,
  getCompanyDetail,
  isfavoriteZp,
  pfavorite,
  deletePfavorite,
  applyzw,
  getJobCanTalk,
  getUserInfo,
  addChatZwRel,
  uploadAction,
  uploadBaseUrl,
} from "@/api/index";
import { startUploadAnalysis } from '../api/resumeApi.js';
import { updateNotifyReadStatus, addBuryingPoint } from "@/api/modules/career";
import ShareMixin from "@/mixins/share";
import ReportShareMixin from "@/mixins/reportShare";
import LoginMixin from "@/mixins/login.js";
import LoginDialog from "@/components/LoginDialog";
import ResumeDeliverDialog from "@/components/ResumeDeliverDialog.vue";
import ChatResume from "./ChatResume.vue";
import { showDelayToastTip } from "@/utils/handle";
import OfferInfoPopup from "./components/OfferInfoPopup";

export default {
  mixins: [ShareMixin, LoginMixin, ReportShareMixin],
  components: {
    LoginDialog,
    ResumeDeliverDialog,
    OfferInfoPopup,
    ChatResume,
  },
  data() {
    return {
      formatHtml,
      notCompany: uni.getStorageSync("login-status") !== "company",
      personId: uni.getStorageSync("person-id").slice(2) || undefined,
      loginStatus: uni.getStorageSync("login-status") || "person",
      zp_id: "",
      pf_id: "",
      info: {},
      chatTo: "",
      zpDetail: {}, // 招聘要求
      comapnyTags: [],
      comapnyDetail: {},
      monMoney: 0,
      showShare: false,
      isCollected: false, // 是否收藏
      canTalk: false,
      shareList: [
        // #ifdef MP-WEIXIN
        {
          text: "转发至微信好友或群聊",
          fcn: this.handleWeChat,
          type: "share",
        },
        // #endif
        // {
        //   text: "生成职位详情长图",
        //   fcn: this.handleLongImg,
        //   type: "",
        // },
        // {
        //   text: "生成职位名片",
        //   fcn: this.handleCard,
        //   type: "",
        // },
        // #ifdef MP-WEIXIN
        {
          text: "生成职位详情小程序码",
          fcn: this.handleCode,
          type: "",
        },
        // #endif
      ],
      selfInfo: getApp().globalData.imInfo,
      publishPersonInfo: {},
      headerPic: "",
      chatId: undefined,
      consultant_entrance_hot:
        this.$imgBaseSelf + "careerPath/consultant_entrance_hot.png",
      isTXJob: false, // 是否腾讯职位
      TXUrls: "https://join.qq.com/post.html ", // 腾讯校招平台

      resumeDeliveryInfo: {},
      activityId: "",
      source: "g", // 因为二维码传值长度限制，代表高校gaoxiaosaas，默认是从高校SaaS页面扫二维码进来,

      didShowPopup: false, // 是否已经显示过OfferInfoPopup
      isShowOfferInfoPopup: false, // 当前是否显示OfferInfoPopup
      isFromEnterprisesActivityHoverBtn: false, // 是否来自名企汇活动按钮
      offerparAdvPic: this.$imgBaseSelf + "offerpai/adv1.png",
      offerparTypeHasBtn: true, // 是否有按钮
      customizedResumeDialog: false, // 定制简历弹窗
      btnCustomStyle: {
        background: "transparent",
      },
      chatResumeDialog: false,
      resumeId: '',
      isShowFile: false,
      file: {},
      uploadLoading: false,
      fileUrl: '',
    };
  },
  filters: {
    timeFilter(val) {
      return val && val.slice(0, 10);
    },
  },
  computed: {
    deliverText() {
      let text = "申请职位";
      if (this.info.zptype == 0) {
        text = "已停招";
      } else if (this.info.can_apply == 0) {
        text = "已投递";
      }
      return text;
    },
    canApply() {
      if (this.info.zptype == 0) return false;
      if (this.info.can_apply != 1) return false;
      return true;
    },
    calculateCompanyName() {
      if (this.info.cname) {
        return this.info.cname;
      }
      return this.info.cname_all;
    },
  },
  onLoad(opt) {
    this.activityId = opt.activityId;
    this.positionId = opt.positionId;
    this.zp_id = opt.jobId;
    if (opt.scene) {
      const scene = decodeURIComponent(opt.scene);
      const fields = scene.split("&");
      const paramsObj = {};
      fields.forEach((field) => {
        const keyValue = field.split("=");
        const key = keyValue[0];
        const value = keyValue[1];
        paramsObj[key] = value;
      });
      this.zp_id = paramsObj.jobId ? paramsObj.jobId : paramsObj.zp_id;
      this.source = paramsObj.sc && paramsObj.sc == "g" ? "gaoxiaosaas" : "";
      if (this.personId) {
        const etId = paramsObj.etId ? paramsObj.etId : "";
        if (etId) {
          const params = {
            etId, // 来自高校SaaS的二维码扫码进来的，就是 40051
            personId: uni.getStorageSync("person-id").slice(2) || "",
            cardType: uni.getStorageSync("cardType") || "",
            eventType: 20,
            sourceType: 10,
            jumpSource: 10,
          };
          this.addBuryingPointFn(params);
        }
      }
    }
    if (opt.form === "enterprisesActivityHoverBtn") {
      this.isFromEnterprisesActivityHoverBtn = true;
    }

    this.getJobDetail();
    this.getZpTxtDetail();
    this.getFavoriteStatus();
    this.canTalkTo();
    this.sharePath =
      `/pagesSub/public/jobDetail/index?jobId=${this.zp_id}` +
      "&positionId=" +
      this.positionId;
    this.shareQuery = `jobId=${this.zp_id}` + "&positionId=" + this.positionId;
    this.updateNotifyStatus(); //记录从短信链接打开小程序订阅内容
  },
  // onShareAppMessage() {
  //   return {
  //     title: this.info.cname_all + " - " + this.info.jtzw,
  //     path: `/pagesSub/public/jobDetail/index?jobId=${this.zp_id}`,
  //   };
  // },
  // onShareTimeline() {
  //   return {
  //     title: this.info.cname_all + " - " + this.info.jtzw,
  //     path: `/pagesSub/public/jobDetail/index?jobId=${this.zp_id}`,
  //   };
  // },
  onShow() {
    this.personId = uni.getStorageSync("person-id").slice(2) || undefined;
  },
  methods: {
    //普通的埋点
    async addBuryingPointFn(params) {
      const res = await addBuryingPoint(params);
    },
    handleConsultantEntranceClick() {
      //职位详情咨询顾问按钮点击事件
      wx.reportEvent("job_detail_consultant_click", {});
      const personId = uni.getStorageSync("person-id").slice(2) || "";
      if (personId) {
        const params = {
          etId: 20027,
          personId,
          cardType: uni.getStorageSync("cardType") || "",
          consultantId: uni.getStorageSync("sellId")
            ? uni.getStorageSync("sellId")
            : "",
          originType: this.originFrom == "shareLink" ? 10 : 20,
        };
        this.addBuryingPointFn(params);
      }
      uni.navigateTo({
        url: "/pagesSub/userCenter/careerPathV2/components/CBuyPage?etId=20027",
      });
    },
    toChat() {
      var personId = uni.getStorageSync("person-id").slice(2) || undefined;
      if (!personId) {
        //this.$refs.loginDialog.setVisibility(true);
        return;
      }
      console.log("chatId", this.chatId);
      if (!this.chatId || this.chatId == "") {
        showDelayToastTip("该用户没有IM账号", 50);
        return true;
      }
      // 是否登录im
      var isIMLogin =
        getApp().globalData.tim && getApp().globalData.tim.getLoginUser();
      if (!isIMLogin) {
        uni.showLoading({
          title: "正在连接",
          mask: true,
        });
        let isFirst = true;
        new IMEventHandler(() => {
          if (isFirst) {
            isFirst = false;
            uni.hideLoading();
            uni.navigateTo({
              url: "/pagesSub/message/chat/index?chatId=" + this.chatId,
            });
          }
        });
      } else {
        uni.navigateTo({
          url: "/pagesSub/message/chat/index?chatId=" + this.chatId,
        });
      }
    },
    // 获取职位详情
    getJobDetail() {
      let params = {
        zp_id: this.zp_id,
        person_id: this.personId,
        Prnd: getApp().globalData.userInfo && getApp().globalData.userInfo.Prnd,
      };
      getZpDetailAndApplyStatus(params).then((res) => {
        var jobdata = res.data || res;
        jobdata.uptime = (jobdata.updatetime || "").substr(0, 10);
        if (jobdata.gznum1 == 0 && jobdata.gznum2 == 0) {
          jobdata.gznum = "经验不限";
        } else if (jobdata.gznum1 == 0 && jobdata.gznum2 > 0) {
          jobdata.gznum = jobdata.gznum1 + "年以下";
        } else if (jobdata.gznum1 > 0 && jobdata.gznum2 == 0) {
          jobdata.gznum = jobdata.gznum1 + "年以上";
        } else if (jobdata.gznum1 > 0 && jobdata.gznum2 > 0) {
          jobdata.gznum = jobdata.gznum1 + "-" + jobdata.gznum2 + "年";
        }
        if ((jobdata.ComTrade || []).length > 15) {
          jobdata.ComTrade = jobdata.ComTrade.substr(0, 15) + "...";
        }

        if (!jobdata.edus) {
          jobdata.edus = "学历不限";
        }
        this.info = jobdata;

        this.shareTitle = this.info.cname_all + " - " + this.info.jtzw;
        this.shareContent.contentTitle = this.shareTitle;
        this.shareContent.contentType = "50";
        this.shareContent.contentId = this.zp_id;

        if (jobdata.urls && jobdata.urlsType == 2) {
          this.isTXJob = true;
          this.TXUrls = jobdata.urls;
        }

        this.getComapnyTags();
        this.getCompanyDetail();
        this.reqBatchGetBingdingPersonInfo();
      });
    },

    // 获取职位发布人信息
    reqBatchGetBingdingPersonInfo() {
      let params = {
        jobidArr: this.zp_id,
      };
      batchGetBingdingPersonInfo(params).then((res) => {
        if (res.code == 200) {
          if (Array.isArray(res.data)) {
            this.publishPersonInfo = res.data[0];
          }
          this.headerPic = this.publishPersonInfo.pic;
          this.chatId = this.publishPersonInfo.jgimid;
        }
      });
    },

    // 收藏状态
    getFavoriteStatus() {
      let data = {
        person_id: this.personId,
        zp_id: this.zp_id,
      };
      isfavoriteZp(data).then((res) => {
        if (res && res.pf_id) {
          this.pf_id = res.pf_id;
          this.isCollected = true;
        } else {
          this.isCollected = false;
        }
      });
    },

    // 收藏
    collect() {
      let data = {
        person_id: this.personId,
        job_id: this.zp_id,
      };
      pfavorite(data).then((res) => {
        this.isCollected = !this.isCollected;
      });
    },

    // 取消收藏
    unCollect() {
      let data = {
        person_id: this.personId,
        pf_id: this.pf_id,
      };
      deletePfavorite(data).then((res) => {
        this.isCollected = !this.isCollected;
      });
    },

    //获取职位要求
    getZpTxtDetail() {
      let data = {
        zp_id: this.zp_id,
        conditionArr: JSON.stringify({ job_skill: 1 }),
      };
      getZpTxtDetail(data).then((res) => {
        this.zpDetail = res.data || res;
      });
    },

    // 公司详情
    getCompanyDetail() {
      let data = {
        company_id: this.info.uid,
      };
      getCompanyDetail(data).then((res) => {
        this.comapnyDetail = res.data || res;
        this.comapnyDetail.logopath = httpToHttps(this.comapnyDetail.logopath);
      });
    },

    // 公司福利
    getComapnyTags() {
      let params = {
        company_id: this.info.uid,
      };
      getComapnyTags(params).then((res) => {
        let data = res.data || res;
        if (data && data.length && data !== "null") {
          this.comapnyTags = res.data || res;
        }
      });
    },

    handleCompany() {
      uni.navigateTo({
        url: "/pagesSub/public/companyDetail/index?companyId=" + this.info.uid,
      });
    },
    handleCollect() {
      this.personId = uni.getStorageSync("person-id").slice(2) || undefined;
      if (!this.personId) {
        this.$refs.loginDialog.setVisibility(true);
        return;
      }
      if (this.isCollected) {
        this.unCollect();
      } else {
        this.collect();
      }
    },
    handleChat() {
      this.personId = uni.getStorageSync("person-id").slice(2) || undefined;
      if (!this.personId) {
        this.$refs.loginDialog.setVisibility(true);
        return;
      }
      // 是否登录im
      var isIMLogin =
        getApp().globalData.tim && getApp().globalData.tim.getLoginUser();
      if (!isIMLogin) {
        // uni.showModal({
        //   title: "温馨提醒",
        //   content: "消息断线，请连接后重试",
        //   success: function (res) {
        //     if (res.confirm) {
        uni.showLoading({
          title: "正在连接",
          mask: true,
        });
        let isFirst = true;
        new IMEventHandler(() => {
          if (isFirst) {
            isFirst = false;
            uni.hideLoading();
            uni.navigateTo({
              url:
                "/pagesSub/message/chat/index?chatId=" +
                this.chatTo +
                "&zpId=" +
                this.zp_id,
            });
          }
        });
        //     }
        //   },
        // });
      } else {
        uni.navigateTo({
          url:
            "/pagesSub/message/chat/index?chatId=" +
            this.chatTo +
            "&zpId=" +
            this.zp_id,
        });
      }
    },

    // 放弃机会，直接投递
    handleOfferInfoPopupwaiveClick() {
      this.isShowOfferInfoPopup = false;
      this.handleDeliver();
    },

    // 点击了offer提示view
    handleOfferBannerClick() {
      this.offerparTypeHasBtn = false; // 设置无按钮
      this.isShowOfferInfoPopup = true;
      this.didShowPopup = true;
    },

    handleDeliver() {
      if (this.activityId == "2031721125699544") {
        const limitTime = new Date("2024/10/12").getTime();
        const nowTime = new Date().getTime();
        if (nowTime < limitTime) {
          uni.showToast({
            icon: "none",
            title: "10月12日开放，敬请期待",
          });
          return false;
        }
      }
      this.personId = uni.getStorageSync("person-id").slice(2) || undefined;
      if (!this.personId) {
        this.$refs.loginDialog.setVisibility(true);
        return;
      }

      if (this.isFromEnterprisesActivityHoverBtn && !this.didShowPopup) {
        const storedValue = uni.getStorageSync('buttonClicked_' + this.personId);
        if (storedValue !== 'true') {
          this.offerparTypeHasBtn = true; // 设置有按钮
          this.isShowOfferInfoPopup = true;
          this.didShowPopup = true;
          return;
        }
      }

      if (this.info.zptype == 0) {
        return uni.showToast({
          title: "该职位已停招",
          icon: "none",
        });
      }
      if (this.info.can_apply != 1) {
        return uni.showToast({
          title: "三天内不能对同一职位进行重复投递",
          icon: "none",
        });
      }
      const params = {
        etId: 50050,
        personId: this.personId,
        cardType: uni.getStorageSync("cardType") || "",
        consultantId: "",
        originType: 20,
        eventData: JSON.stringify({
          jobId: this.zp_id,
        }),
      };
      this.addBuryingPointFn(params);
      this.verifyResumeDelivery();
      // this.applyto();
    },
    handleShare(item) {
      this.showShare = false;
      this.$nextTick(item.fcn);
    },
    handleWeChat() {},
    handleLongImg() {},
    handleCard() {},
    handleCode() {},

    //判断是否有沟通功能
    canTalkTo: function () {
      let data = {
        job_id: this.zp_id,
      };
      getJobCanTalk(data).then((res) => {
        if (res && +res.code === 200) {
          this.chatTo = res.info.company_default_im_id;
          let param = {
            uname: this.chatTo,
          };
          getUserInfo(param).then((infoRes) => {
            if (infoRes && +infoRes.code === 200) {
              this.canTalk = true;
            }
          });
        }
      });
    },

    // 获取投递职位的参数
    getApplyPositionParams() {
      var data = {
        sendtype: "normal",
        title: "求职信",
        mailtext: "贵公司，您好，我基本符合以上职位的条件，应聘该职，谢谢！",
        cmid: this.info.uid,
        zwid: this.info.id,
        jobname: this.info.jtzw,
        job1001UserId: this.personId,
        monMoney: this.monMoney,
        tjsalarArr: JSON.stringify({
          changemonth: "1",
          salary_month: this.monMoney,
          changeyear: "1",
        }),
      };
      return data;
    },

    // 投递简历校验
    verifyResumeDelivery() {
      this.$refs.resumeDeliverDialog.verifyResumeDelivery({
        companyId: this.info.uid,
        positionId: this.info.id,
        jobName: this.info.jtzw,
        personId: this.personId,
        activityId: this.activityId,
        source: this.source,
      });
    },

    hanldeDeliverySuccess() {
      this.info.can_apply = 0;
    },

    //投递职位
    applyto: function () {
      uni.showLoading({
        title: "投递中",
        mask: false,
      });
      var data = this.getApplyPositionParams();
      applyzw(data)
        .then((res) => {
          uni.hideLoading();
          var _data = res;
          if (_data.status == "OK") {
            uni.showToast({
              icon: "none",
              title: "申请成功",
            });
            this.info.can_apply = 0;
          } else {
            if (_data.code == "101" || _data.code == "102") {
              uni.showModal({
                title: "提示",
                content: "您的简历未完善，填写完善后即可投递简历",
                success: function (modalRes) {
                  if (modalRes.confirm) {
                    uni.navigateTo({
                      url: "/pagesSub/newResume/index",
                    });
                  }
                },
              });
            } else {
              uni.showToast({
                title: _data.status_desc,
                icon: "none",
              });
            }
          }
        })
        .catch((err) => {
          uni.hideLoading();
        });
    },

    // 发送单聊文本消息
    sendSingleTextMsg(text) {
      if (!text) {
        return uni.showToast({
          icon: "none",
          title: "发送内容不能为空",
        });
      }
      let param = {
        target_username: this.chatTo,
        content: JSON.stringify({
          send_uid: this.selfInfo.uname,
          receive_uid: this.chatTo,
          content: text,
          person_iname: this.selfInfo.nickname,
          person_pic: this.selfInfo.pic,
          is_send: "1",
          idate: new Date().getTime(),
          type: 1,
        }),
        no_offline: false,
        no_notification: false,
        custom_notification: {
          enabled: true,
          title: this.selfInfo.nickname,
          alert: text,
        },
        need_receipt: true,
      };
      getApp()
        .globalData.tim.sendSingleMsg(param)
        .onSuccess((data, msg) => {
          this.handleSendMsgSuccess(data, msg);
          getApp().globalData.bus.$emit("NEED_UPDATE_CONVERSATION");
        })
        .onFail((res) => {
          uni.showToast({
            icon: "none",
            title: "消息发送失败",
          });
        });
    },
    // 成功发送消息处理
    handleSendMsgSuccess(data, msg) {
      this.sendText = "";
      msg.ctime_ms = data.ctime_ms;
      let msgList = getApp().globalData.messageList.filter(
        (ele) => ele.from_username == this.chatTo
      );
      if (!msgList.length) {
        let msgItem = {
          from_username: msg.target_name,
          msgs: [msg],
        };
        getApp().globalData.messageList.push(msgItem);
      } else {
        msgList[0].msgs.push(msg);
      }
    },
    // 关联职位
    addChatZwRel() {
      let params = {
        person_id: this.personId,
        company_im_id: this.chatTo,
        zw_id: this.zp_id,
        from_who: this.loginStatus,
        conditionArr: "",
      };
      addChatZwRel(params).then((res) => {});
    },
    // 登录前页面
    saveReturnUrl() {
      let fullPath =
        getCurrentPages()[getCurrentPages().length - 1].$page.fullPath;
      let returnUrl = encodeURIComponent(fullPath);
      return returnUrl;
    },
    loginSuccessBack() {
      const params = {
        etId: 40051,
        personId: uni.getStorageSync("person-id").slice(2) || "",
        cardType: uni.getStorageSync("cardType") || "",
        eventType: 20,
        sourceType: 10,
        jumpSource: 10,
      };
      this.addBuryingPointFn(params);
      this.getJobDetail();
      this.getZpTxtDetail();
      this.getFavoriteStatus();
      this.canTalkTo();
      this.sharePath =
        `/pagesSub/public/jobDetail/index?jobId=${this.zp_id}` +
        "&positionId=" +
        this.positionId;
      this.shareQuery =
        `jobId=${this.zp_id}` + "&positionId=" + this.positionId;
      this.updateNotifyStatus(); //记录从短信链接打开小程序订阅内容
    },
    updateNotifyStatus() {
      let params = {
        dataId: this.zp_id,
      };
      // console.log("xxxxxxxx小程序段链接updateNotifyStatus进入订阅通知xxxxxxxxxxx",params);
      updateNotifyReadStatus(params).then((res) => {
        if (res && res.code == 200) {
          // console.log(
          //   "------------点击进入职讯记录成功---------职位详情---------------"
          // );
          // uni.showToast({
          //   icon: "none",
          //   title: "点击进入职讯",
          // });
        } else {
          // uni.showToast({
          //   icon: "none",
          //   title: res.status_desc,
          //   duration: 1000,
          // });
        }
      });
    },
    copyText(text) {
      uni.setClipboardData({
        data: text,
        success: function (res) {
          uni.showToast({
            title: "复制成功",
            icon: "success",
          });
        },
      });
    },
    handleCustomizedResume() {
      this.customizedResumeDialog = true;
    },
    handleChatToCustomizedResume() {
      this.personId = uni.getStorageSync("person-id").slice(2) || undefined;
      if (!this.personId) {
        this.$refs.loginDialog.setVisibility(true);
        this.customizedResumeDialog = false;
        return;
      }

      this.customizedResumeDialog = false;
      this.chatResumeDialog = true;
      this.$refs.chatResume.getQuestions();
    },
    formatFileSize(size) {
      if (!size) {
        return "";
      }
      if (size < 1024) {
        return size + "B";
      } else if (size < 1048576) {
        return (size / 1024).toFixed(1) + "KB";
      } else if (size < 1073741824) {
        return (size / 1048576).toFixed(1) + "MB";
      } else {
        return (size / 1073741824).toFixed(1) + "GB";
      }
    },
    handleUploadResume() {
      this.personId = uni.getStorageSync("person-id").slice(2) || undefined;
      if (!this.personId) {
        this.$refs.loginDialog.setVisibility(true);
        this.customizedResumeDialog = false;
        return;
      }

      // #ifdef H5
      var uploadApi = uni.chooseFile;
      // #endif
      // #ifdef MP-WEIXIN
      var uploadApi = wx.chooseMessageFile;
      // #endif
      const TYPE = [".doc", ".docx", ".png", ".jpg", ".jepg", ".png", ".pdf"];
      let that = this;
      uploadApi({
        count: 1,
        extension: TYPE,
        success: (res) => {
          let tempFilePaths = res.tempFiles;
          let fileExt = "." + tempFilePaths[0].name.replace(/.+\./, "");
          if (TYPE.indexOf(fileExt) < 0) {
            return uni.showToast({
              icon: "none",
              title: "文件类型错误",
            });
          }
          if (tempFilePaths[0].size / (1024 * 1024) > 10) {
            return uni.showToast({
              icon: "none",
              title: "文件大小不能超过10M",
            });
          }

          this.isShowFile = true;

          this.file = {
            name: tempFilePaths[0].name,
            size: this.formatFileSize(tempFilePaths[0].size),
          }
          uni.showLoading({
            title: '正在上传'
          });
          uni.uploadFile({
            url: uploadAction,
            filePath: tempFilePaths[0].path,
            name: "file",
            success: (uploadRes) => {
              uni.showToast({
                icon: "none",
                title: "上传成功",
              });
              this.fileUrl = uploadBaseUrl + uploadRes.data;
            },
          });
        },
      });
    },
    handleStartCustomized() {
      const params = {
        zpId: this.zp_id,
        personId: this.personId,
        fileUrl: this.fileUrl,
      };
      this.uploadLoading = true;
      startUploadAnalysis(params).then(res => {
        if (res.code == 200) {
          uni.navigateTo({
            url: '/pagesSub/public/customizedResume/analysis?type=file&taskId=' + res.data.taskId,
          });
        }
      }).finally(() => {
        this.uploadLoading = false;
      });
    },
  },
};
</script>

<style lang="scss">
$img-base-jdetail: $img-base + "jdetail/";
@include img-base-self(".jc-region::before", "jdetail/address.png?v=1");
@include img-base-self(
  ".jd-option .collect.active::before",
  "jdetail/collected.svg"
);

.account-box {
  display: flex;
  flex-direction: row;
  align-items: center;
  margin-top: 24rpx;
  padding: 32rpx;
  background: $uni-bg-color;
  border-radius: 20rpx;
  .header-pic {
    background: yellow;
    width: 66rpx;
    height: 66rpx;
    //margin-left: 32rpx;
    border-radius: 50%;
  }
  &-right {
    flex: 1;
    display: flex;
    flex-direction: column;
    &-item {
      display: flex;
      flex-direction: row;
      // max-width: 400rpx;
      .text-item {
        margin-top: 10rpx;
        padding-left: 20rpx;
        word-wrap: break-word;
      }
    }
  }
}
.job-detail {
  padding: 32rpx;
  .jd-wrap {
    &.not-company {
      padding-bottom: 144rpx;
    }
    .jd-consultant {
      display: flex;
      align-items: center;
      justify-content: space-between;
      background: linear-gradient(340deg, #fffbf3 0%, #ffffff 100%) !important;
      margin-bottom: 18rpx;
      padding: 16rpx !important;
      margin-top: 0rpx !important;
      &-container {
        display: flex;
        align-items: center;
        .market-icon {
          width: 54rpx;
          height: 54rpx;
          margin-right: 14rpx;
          img {
            width: 54rpx;
            height: 54rpx;
          }
        }
        .market-main-text {
          margin-right: 26rpx;
          font-family: PingFang-SC, PingFang-SC;
          font-weight: bold;
          font-size: 30rpx;
          color: #333333;
          line-height: 36rpx;
          text-align: left;
          font-style: normal;
        }
        .market-sub-text {
          font-family: PingFangSC, PingFang SC;
          font-weight: 400;
          font-size: 24rpx;
          color: #666666;
          line-height: 32rpx;
          text-align: left;
          font-style: normal;
        }
      }
      .market-button {
        padding: 8rpx 28rpx;
        color: white;
        background: #f75a3e;
        font-size: 24rpx;
        border-radius: 28rpx;
        border: 3rpx solid #ffffff;
        font-weight: bold;
      }
    }
    .jd-sect {
      margin-top: 24rpx;
      padding: 32rpx;
      background: $uni-bg-color;
      border-radius: 20rpx;
      &.jd-info {
        margin-top: 0;
        font-size: $uni-font-size-nor;
        line-height: $uni-font-size-base;
        box-shadow: 0px 6rpx 18rpx 2rpx #eee;
        .info-top {
          display: flex;
          align-items: center;
          justify-content: space-between;
          font-size: $uni-font-size-lg;
          line-height: $uni-font-size-lg;
          font-weight: bold;
          .info-salary {
            color: $u-type-primary;
          }
        }
        .info-middle {
          display: flex;
          flex-wrap: wrap;
          align-items: center;
          margin-top: 24rpx;
          color: $uni-text-color-666;
          text {
            display: flex;
            align-items: center;
            margin: 0 24rpx 10rpx 0;
            padding: 4rpx 8rpx;
            border-radius: $uni-border-radius-sm;
            background-color: $uni-bg-color-border-f1;
            &::before {
              content: "";
              display: inline-block;
              margin-right: 4rpx;
              width: 28rpx;
              height: 28rpx;
              background-size: 100% 100%;
            }

            &.info-region {
              &::before {
                background-image: url($img-base-jdetail + "region.png");
              }
            }
            &.info-exp {
              &::before {
                background-image: url($img-base-jdetail + "exp.png");
              }
            }
            &.info-edu {
              &::before {
                background-image: url($img-base-jdetail + "edu.png");
              }
            }
            &.info-type {
              margin-right: 0;
              &::before {
                background-image: url($img-base-jdetail + "time.png");
              }
            }
          }
        }
        .info-bottom {
          margin-top: 14rpx;
          color: $uni-text-color-555;
        }
      }

      &.jd-company {
        .jc-info {
          display: flex;
          .info-avatar {
            margin-right: 24rpx;
            image {
              width: 140rpx;
              height: 85rpx;
              border-radius: 16rpx;
              border: 1rpx solid $uni-bg-color-border-d9;
            }
          }
          .info-desc {
            font-size: $uni-font-size-base;
            line-height: $uni-font-size-lg;
            .id-name {
              font-size: $uni-font-size-lg;
              line-height: $uni-font-size-max;
              font-weight: bold;
            }
            .id-trade {
              margin-top: 16rpx;
              color: $uni-text-color-999;
            }
            .id-other {
              display: flex;
              align-items: center;
              margin-top: 16rpx;
              color: $uni-text-color-999;
              .divider {
                margin: 0 8rpx;
                width: 1rpx;
                height: 26rpx;
                background: $uni-text-color-888;
              }
            }
          }
        }
        .jc-region {
          display: flex;
          align-items: flex-start;
          margin-top: 32rpx;
          padding-top: 32rpx;
          font-size: $uni-font-size-base;
          line-height: $uni-font-size-lg;
          color: $uni-text-color-666;
          &::before {
            content: "";
            display: inline-block;
            flex-shrink: 0;
            margin-right: 8rpx;
            width: 32rpx;
            height: 32rpx;
            background-size: 100% 100%;
          }
        }
      }
      &.jd-benefit {
        display: flex;
        flex-wrap: wrap;
        padding: 32rpx 16rpx 16rpx 32rpx;
        .jb-item {
          margin-right: 16rpx;
          margin-bottom: 16rpx;
          padding: 12rpx;
          background: $uni-bg-color-border-f1;
          border-radius: $uni-border-radius-sm;
          font-size: $uni-font-size-sm;
          line-height: $uni-font-size-sm;
          color: $uni-text-color-tag;
        }
      }
      &.jd-request {
        .jr-title {
          position: relative;
          font-size: $uni-font-size-lg;
          line-height: $uni-font-size-big;
          font-weight: bold;
        }
        .jr-cont {
          margin-top: 32rpx;
          padding-top: 24rpx;
          font-size: $uni-font-size-nor;
          line-height: $uni-font-size-max;
        }

        .customized-resume {
          position: absolute;
          right: 0px;
          top: 0;
          padding: 6rpx 24rpx;
          color: #F04646;
          border-radius: 26rpx;
          border: 2rpx solid #F04646;
          display: inline-block;
          font-size: 26rpx;

          .icon-analysis {
            margin-right: 6rpx;
            width: 28rpx;
            height: 28rpx;
            background-image: url($img-base + "resume/analysis.png");
          }
        }
      }
    }
  }
  .jd-option {
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: fixed;
    bottom: 0;
    left: 0;
    z-index: 2;
    padding: 24rpx 32rpx;
    padding-bottom: calc(32rpx + constant(safe-area-inset-bottom));
    padding-bottom: calc(32rpx + env(safe-area-inset-bottom));
    width: 100vw;
    color: $uni-text-color-666;
    background: $uni-bg-color;
    white-space: nowrap;
    box-sizing: border-box;
    .option-rich {
      flex-shrink: 0;
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: space-between;
      margin-right: 32rpx;
      width: 70rpx;
      font-size: $uni-font-size-min;
      line-height: $uni-font-size-sm;
      &::before {
        content: "";
        display: inline-block;
        margin-bottom: 4rpx;
        width: 54rpx;
        height: 54rpx;
        background-size: 100% 100%;
      }
      &.share {
        background: transparent;
        border: none;
        &::before {
          background-image: url($img-base-jdetail + "share.png");
        }
        &::after {
          display: none;
        }
        &.button-hover {
          background: transparent;
          color: $uni-text-color-222;
        }
      }
      &.collect {
        margin-right: 38rpx;
        &::before {
          background-image: url($img-base-jdetail + "collect.png");
        }
        &.active {
          color: $u-type-primary;
        }
      }
    }
    .option-btn {
      flex-grow: 1;
      margin: 0;
      height: 88rpx;
      line-height: 88rpx;
      box-sizing: border-box;
      ::v-deep button {
        height: 88rpx;
        line-height: 88rpx;
      }
      &.chat {
        margin-right: 16rpx;
        width: 468rpx;
        border-color: $u-type-primary;
        background: $uni-bg-color;
        color: $u-type-primary;
        ::v-deep .u-btn {
          border-color: $u-type-primary;
          background: $uni-bg-color;
          color: $u-type-primary;
          &::after {
            border-color: $u-type-primary;
            border-width: 4rpx;
          }
        }
        &::after {
          border-color: $u-type-primary;
          border-width: 4rpx;
          border-radius: 10rpx !important;
        }
      }
      &.deliver {
        width: 468rpx;
        border-radius: 10rpx !important;
        background: $bg-linear-gradient-button;
        &.btn-disable {
          ::deep-vue .btn-disable {
            background-color: #eaeaec;
          }
        }
      }
    }
  }
}
.share-item {
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 34rpx 0;
  background: transparent;
  border: none;
  font-size: $uni-font-size-lg;
  line-height: 1;
  border-radius: 0 !important;
  &::after {
    border-radius: 0 !important;
  }
  &.close {
    border-top: 12rpx solid #eaeaec;
    &::after {
      display: none;
    }
  }
}
.icon-require {
  width: 30rpx;
  height: 30rpx;
  margin-top: -8rpx;
  margin-right: 16rpx;
  background-image: url($img-base-jdetail + "require.png");
  background-size: 100% 100%;
}

.tx-job {
  margin-top: 24rpx;
  padding: 24rpx;
  color: #ffffff;
  border-radius: 16rpx;
  background-color: #f75a3e;
}
.offer-advbox {
  height: 225rpx; 
  width: 100%;
  background-image: url($img-base + "offerpai/adv1.png");
  background-size: 100% 100%;
  margin-top: 24rpx;
}

.resume-popup {
  padding: 0 30rpx 64rpx 30rpx;

  .text {
    font-size: 26rpx;
    color: #222222;
  }

  .text-bottom {
    margin-top: 32rpx;
  }

  .resume-popup-bg {
    width: 232rpx;
    height: 84rpx;
    background: rgba(255, 167, 167, 0.6);
    filter: blur(86rpx);
    position: absolute;
    top: -8rpx;
    right: 98px;
  }

  .resume-popup-bg-2 {
    position: absolute;
    top: -8rpx;
    right: -20rpx;
    width: 228rpx;
    height: 88rpx;
    background: rgba(78, 224, 229, 0.6);
    filter: blur(68rpx);
  }
}

.customized-resume-title {
  padding: 84rpx 0 42rpx 0;
  font-size: 48rpx;
  font-weight: 600;
  color: #141414;
}

.customized-resume-img {
  width: 100%;
}

.btn-start-chat, .btn-upload-resume {
  display: inline-block;
  height: 88rpx;
  line-height: 88rpx;
  font-size: 28rpx;
  border-radius: 44rpx;
  text-align: center;
}

.btn-start-chat {
  width: 234rpx;
  background: transparent;
  color: #F04646;
  border: 1px solid #F04646;
  margin-right: 22rpx;
}

.btn-upload-resume {
  width: 432rpx;
  color: #ffffff;
  background-color: #F04646;
}

.customized-action {
  margin-top: 32rpx;
}

.resume-file {
  .start-chat {
    margin-top: 32rpx;
    color: $u-type-primary;
    text-align: center;
  }

  .icon-file {
    flex-shrink: 0;
    width: 60rpx;
    height: 64rpx;
    margin-right: 22rpx;
    background-image: url($img-base + "message/" + "file.png");
  }

  .change-file {
    margin-right: 24rpx;
    color: $u-type-primary;
  }

  .file-name {
    width: 280rpx;
  }
}

.file-item {
  display: flex;
  align-items: center;
  padding: 24rpx 32rpx;
  border-radius: 10rpx;
  box-shadow: 0rpx 4rpx 8rpx 7rpx rgba(0,0,0,0.05);
  margin-top: 33rpx;

  .flex-1 {
    flex-grow: 1;
  }
}

</style>
